<template>
    <div>
        <el-form ref="ruleForm" :model="obj" :rules="rules">
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label="原始信息：" prop="msg" :label-width="formLabelWidth3">
                        <el-input size="small" v-model="obj.msg" type="textarea" :rows="4"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label="地址：" prop="address" :label-width="formLabelWidth3">
                        <el-input size="small" v-model="obj.address"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label="签名：" prop="sigstr" :label-width="formLabelWidth3">
                        <el-input size="small" v-model="obj.sigstr" type="textarea" :rows="5"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row :gutter="1">
                <el-col :span="24">
                    <el-form-item label="" prop="title" :label-width="formLabelWidth3">
                        <el-button type="primary" size="small" @click="checkMsg">验证</el-button>
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
    </div>
</template>

<script>
    export default {
        name: 'Message',
        data() {
            return {
                formLabelWidth1: '60px',
                formLabelWidth2: '80px',
                formLabelWidth3: '86px',
                obj:{
                    msg: '',
                    address: '',
                    sigstr: '',
                },
                rules: {
                    msg: [
                        {required: true, message: '请输入信息', trigger: ['blur', 'change']}
                    ],
                    address: [
                        {required: true, message: '请输入地址', trigger: ['blur', 'change']}
                    ],
                    sigstr: [
                        {required: true, message: '请输入签名', trigger: ['blur', 'change']}
                    ],
                },
            }
        },
        props: ['proParm'],
        methods: {
            checkMsg() {
                this.$refs['ruleForm'].validate(async (valid) => {
                    if (valid) {
                        try {
                            let result = messageVerify(this.proParm, this.obj.address, this.obj.msg, this.obj.sigstr);
                            if (result === true) {
                                this.$message({
                                    type: 'success',
                                    message: '验证通过'
                                });
                            } else {
                                this.$message({
                                    type: 'error',
                                    message: '验证失败'
                                });
                            }
                        }
                        catch (e) {
                            this.$message({
                                type: 'error',
                                message: '验证失败'
                            });
                        }
                    }
                    else {
                        return false;
                    }
                });
            }
        }
    }
</script>

<style scoped lang="less">
    /deep/ .el-form-item__label{
        padding: 0 5px 0 0;
    }
</style>
